'''
Created on Mar 7, 2016

@author: JimmyMo
'''
import time
import inspect
from processor.perfsynprocessor import Processor

class Writter(Processor):
    def __init__(self):
        self.enable_buffer = False
        self.event_buffer_size = 600000
        self.event_buffer_list = []
        self._parse_options()
    def _parse_options(self):
        '''abstract method'''
        class_name = self.__class__.__name__
        method_name = inspect.stack()[0][3]
        raise Exception("%s method in class %s is abstract method which is not implemented..." % (method_name, class_name))
    def _process(self, current_event_list, prior_event_list):
        self.event_buffer_list.extend(current_event_list)
        if (not self.enable_buffer) or (len(self.event_buffer_list) >= self.event_buffer_size):
            self.write()
            self.event_buffer_list = []
              
    def write(self):
        real_class_name =  self.__class__.__name__
        now = time.clock()
        time.clock()
        self._write()
        elapsed = time.clock() - now
        print("%s writting took %fs" % (real_class_name, elapsed))
        
    def _write(self):
        '''abstract method'''
        class_name = self.__class__.__name__
        method_name = inspect.stack()[0][3]
        raise Exception("%s method in class %s is abstract method which is not implemented..." % (method_name, class_name))
    
    